package video.web;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import util.GetHtml;


/**
 * url example http://www.tudou.com/programs/view/60A6FTdbL2U
 * @author ladjzero
 *
 */
public class Tudou extends SuperParser{

	public Tudou(String videoUrl) {
		super(videoUrl);
	}
	
	public boolean isReachable(){
		if( null == content)
			return false;
		return true;
	}
	
	public String getFileUrl(){
		String iid = null;
		Pattern pattern = Pattern.compile(",iid = ([0-9]+)");
		Matcher matcher = pattern.matcher("");
		if(null!=content)
			matcher = pattern.matcher(content);
		while(matcher.find())
			iid = matcher.group(1);
		
		String xml = new GetHtml().get("http://v2.tudou.com/v?vn=02&st=1%2C2&it="+iid);
		pattern = Pattern.compile(">http(.+?)</f>");
		matcher = pattern.matcher("");
		if(null!=xml)
			matcher = pattern.matcher(xml);
		while(matcher.find())
			return "http"+matcher.group(1);
		return null;
 
	}
	
	public String getImage(){
		Pattern pattern = Pattern.compile(",lpic = \"(.+?)\"");
		Matcher matcher = pattern.matcher("");
		if(null!=content)
			matcher = pattern.matcher(content);
		while(matcher.find())
			return matcher.group(1);
		return null;
	}
	
	public String getSwf(){
		return "http://www.tudou.com/v/"+vid;
	}
	

}
